<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller {

    function __construct(){
        parent::__construct();
        $this->load->model('pages_model');
        #$this->output->enable_profiler(true);
    }

    function index($url_friendly = ''){
        $url_friendly = $url_friendly;
        $info         = $this->pages_model->url_friendly($url_friendly);
        if (count($info) > 0) {
            $data['url']   = $url_friendly;
            $data['pages'] = $this->pages_model->get_many_by(array('type' => $info->type, 'id !=' => $info->id));
            $data['info']  = $info;
            $data['tpl']   = 'pages/index';
            $this->load->view('_layout/index', $data);
        } else {
            redirect('404.html');
        }
    }

    function detail($page_id = 0){
        $page_id = intval($page_id);
        if ($page_id != 0){
            $data['data'] = $this->pages_model->get_page($page_id);

            if (count($data['data']) == 0){
                redirect('');
            }

            $data['meta_title']    = $data['data']['title']." - ".$this->config->item('website_name'). ' | '.$this->config->item('website_domain');
            $data['meta_keyword']  = $this->config->item('website_keyword');
            $data['meta_desc']     = $this->config->item('website_desc');

            $data['tpl']               = 'pages/index';
            $this->load->view('_layout/index', $data);
        } else {
            redirect('');
        }
    }

	function detail_single($page_id = 0, $field=''){
        $page_id = intval($page_id);
        if ($page_id != 0){
            $data['data'] = $this->pages_model->get_page($page_id);

            if (count($data['data']) == 0){
                redirect('');
            }

            $data['meta_title']    = $data['data']['title']." - ".$this->config->item('website_name'). ' | '.$this->config->item('website_domain');
            $data['meta_keyword']  = $this->config->item('website_keyword');
            $data['meta_desc']     = $this->config->item('website_desc');
			$data['field'] = $field;
            $data['tpl']               = 'pages/detail_single';
            $this->load->view('_layout/single', $data);
        } else {
            redirect('');
        }
    }

    function category($type = 0){

    }
}